﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using net.veekee.common;
using net.veekee.common.data;
using net.veekee.logprocessor.plugin.input;
using PcapDotNet.Packets;

namespace net.veekee.logprocessor.plugin.wireshark
{
    public class PCAPEntry : FileEntry
    {
        public Packet Packet = null;

        public PCAPEntry RecoverPreviousTCPIP()
        {
            var lst = AParser.GetInstance().entries.Where(p =>
                ((PCAPEntry)p).Packet.Ethernet.IpV4.Source.Equals(this.Packet.Ethernet.IpV4.Destination) &&
                ((PCAPEntry)p).Packet.Ethernet.IpV4.Destination.Equals(this.Packet.Ethernet.IpV4.Source) &&
                ((PCAPEntry)p).Packet.Ethernet.IpV4.Tcp.DestinationPort.Equals(this.Packet.Ethernet.IpV4.Tcp.SourcePort) &&
                ((PCAPEntry)p).Packet.Ethernet.IpV4.Tcp.SourcePort.Equals(this.Packet.Ethernet.IpV4.Tcp.DestinationPort) &&
                ((PCAPEntry)p).Packet.Ethernet.IpV4.Tcp.NextSequenceNumber.Equals(this.Packet.Ethernet.IpV4.Tcp.AcknowledgmentNumber)).ToList();

            return lst.FirstOrDefault() as PCAPEntry;
        }
    }
}
